const axios = require("axios");
const sendMessage = (params) => {
  return new Promise((resolve, reject) => {
    const { touser, template_id, access_token, data = {} } = params;
    for (item of touser) {
      axios.post(
        `https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=${access_token}`,
        {
          touser: item,
          template_id,
          data,
        }
      );
    }
    resolve();
  });
};

module.exports = sendMessage;
